
//下安装单
function toAddInstall(object){
	success("正在保存日记中........");
	var rootDiv=$(object).prev().prev();
	var form=rootDiv.find("form");
	if(form.length==1){
		var oneForm=form.first();
		//这第一个form是填写的一个一些基本的信息
		var context=$(oneForm).serialize();
		context =decodeURIComponent(context,true);
		context =JSON.parse(updateString(context));
		var installAddress={};
		installAddress.Province=context.Province2;
		installAddress.City=context.City2;
		installAddress.Village=context.Village2;
		var anzhuang;
		$.post(
				"../chinaArea/getStringByArrayCode.do",
				{
					arrayCode:JSON.stringify(installAddress)
				},
				function(data){
					anzhuang=data.area;
					var quH={};
					quH.Province=context.Province;
					quH.City=context.City;
					quH.Village=context.Village;
					var quHuo;
					$.post(
							"../chinaArea/getStringByArrayCode.do",
							{
								arrayCode:JSON.stringify(installAddress)
							},
							function(data){
								quHuo=data.area;
								var date = context.subscribeTime;
								date = date.substring(0,19);
								date = date.replace(/\+/g," ");
								date = date.replace(/-/g,'/'); 
								var timestamp = new Date(date).getTime();
								$.post(
										"../note/toAddAnzhuangIndent.do",
										{
											name:context.name,
											phone:context.phone,
											subscribeTime:timestamp,
											city:anzhuang,
											address:context.installAdress,
											quHAddress:quHuo+context.quhuo
										},
										function(data){
											if(data!=null){
												success("添加测量日记成功!");
												setTimeout(myfresh,1000);
											}
											
										}
								
								);
							},
							"json"
					);
				},
				"json"
		);		
	}else if(form.length>1) {
		var dataArray=new Array();
		$.each(form,function(i,oneForm){
			if(i==0){
			}else{
				//这是form表格提交的信息
				var context=$(oneForm).serialize();
				context =decodeURIComponent(context,true);
				context =JSON.parse(updateString(context));
				//图片都传到后台, 然后生成地址
				var formId=$(oneForm).attr("id");
				//布存的所有信息  bu_表格id
				var bumishu=$(oneForm).data("bu_"+formId);
				//纱存的所有信息  sha_表格id
				var shamishu=$(oneForm).data("sha_"+formId);
				//帘头存的所有信息 liantou_表格id
				var toumishu=$(oneForm).data("liantou_"+formId);
				//尺寸存的所有信息 chicun_表格id
				var chicun=$(oneForm).data("chicun_"+formId);
				context.bumishu=bumishu;
				context.shamishu=shamishu;
				context.toumishu=toumishu;
				$.each($(oneForm).find('img'),function(aa,imgaa){
					if(aa==1){
						context.merchantsImg=$(imgaa).attr("src");
					}
				});
				if(typeof(bumishu)=="undefined"&&typeof(chicun)=="object"){
					context.bumishu=chicun;
				}
				dataArray[i-1]=context;
				
			}
			
		});
		//有数据的订单提交
		//这第一个form是填写的一个一些基本的信息
		var context=form.first().serialize();
		context =decodeURIComponent(context,true);
		context =JSON.parse(updateString(context));
		var installAddress={};
		installAddress.Province=context.Province2;
		installAddress.City=context.City2;
		installAddress.Village=context.Village2;
		var anzhuang;
		$.post(
				"../chinaArea/getStringByArrayCode.do",
				{
					arrayCode:JSON.stringify(installAddress)
				},
				function(data){
					anzhuang=data.area;
					var quH={};
					quH.Province=context.Province;
					quH.City=context.City;
					quH.Village=context.Village;
					var quHuo;
					$.post(
							"../chinaArea/getStringByArrayCode.do",
							{
								arrayCode:JSON.stringify(installAddress)
							},
							function(data){
								quHuo=data.area;
								var date = context.subscribeTime;
								date = date.substring(0,19);
								date = date.replace(/\+/g," ");
								date = date.replace(/-/g,'/'); 
								var timestamp = new Date(date).getTime();
								$.post(
										"../note/toAddAnzhuangIndent.do",
										{
											name:context.name,
											phone:context.phone,
											subscribeTime:timestamp,
											city:anzhuang,
											address:context.installAdress,
											quHAddress:quHuo+context.quhuo,
											duogechuanglian:JSON.stringify(dataArray)	
										},
										function(data){
											//TODO 没有窗帘信息的返回信息
											if(data!=null){
												success("添加测量日记成功!");
												setTimeout(myfresh,1000);
											}
										}
								
								);
							},
							"json"
					);
				},
				"json"
		);			
		
		
		
	}
	


	
	
}



